package cn.kshost.zqyg.manager.controller;

import cn.kshost.zqyg.manager.service.ProductService;
import cn.kshost.zqyg.model.dto.product.ProductDto;
import cn.kshost.zqyg.model.entity.product.Product;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/admin/product/product")
@Tag(name = "商品表维护")
public class ProductController {

    @Autowired
    ProductService productService;

    @Operation(summary = "条件分页查询")
    @GetMapping("/{pageNum}/{pageSize}")
    public Result getProductList(ProductDto productDto,@PathVariable int pageNum, @PathVariable int pageSize) {
       PageInfo<Product> pageInfo =  productService.getProductList(pageNum,pageSize,productDto);
       return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "新增商品")
    @PostMapping("/save")
    public Result saveProduct(@RequestBody Product Product) {

        productService.save(Product);

        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "商品回显")
    @GetMapping("/getById/{id}")
    public Result<Product> getById(@PathVariable long id) {
        Product product = productService.getById(id);
        return Result.build(product , ResultCodeEnum.SUCCESS) ;
    }

    @Operation(summary = "更新数据")
    @PutMapping("/updateById")
    public Result updateById(@RequestBody Product Product) {
        productService.updateById(Product);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "删除商品")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable long id) {
        productService.deleteById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改商品审核状态")
    @GetMapping("/updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable long id, @PathVariable Long auditStatus){

        productService.updateAuditStatus(id,auditStatus);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "修改商品上架状态")
    @GetMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id, @PathVariable Long status){

        productService.updateStatus(id,status);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }



}
